<%@ tag import="j.framework.core.FApplication" %>
<%@ tag import="j.util.StringUtils" %>
<%@ tag import="j.util.web.ParamUtils" %>
<%@ tag body-content="scriptless" pageEncoding="utf-8" %>
<%@ taglib prefix="j" uri="j/tags" %>

<%--
    action与requestId必须指定其中一个，若指定了requestId，则action的值将忽略
    可在使用此TAG的子页面中定义 doBeforeSave及 doAfterSave两个事件函数
    doBeforeSave方法签名：doBeforeSave($form,_dialogArguments);
    doAfterSave方法签名：doAfterSave(data,_dialogArguments);//data为调用后台保存方法后所传递过来的数据
--%>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="easyui" uri="http://www.joyi.cn/easyui/tags" %>
<%@ attribute name="title" type="java.lang.String" %>
<%
    String base = FApplication.getResourceUrl("/");
    request.setAttribute("base",base);
    if(title==null || title.length()==0){
        title = "对话框";
    }
    request.setAttribute("title",title);
    request.setAttribute("isView", ParamUtils.getBooleanParameter(request, "v"));
%>
<!DOCTYPE html>
<html xmlns=http://www.w3.org/1999/xhtml>
<head>
    <title>对话框</title>
    <link rel="stylesheet" type="text/css" href="${base}widgets/easyui/themes/default/easyui.css?0.1" />
    <link rel="stylesheet" type="text/css" href="${base}widgets/easyui/themes/icon.css" />
    <link rel="stylesheet" type="text/css" href="${base}styles/c.css" />
    <script type="text/javascript" src="${base}js/jquery.min.js"></script>
    <script type="text/javascript" src="${base}widgets/easyui/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="${base}widgets/easyui/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript" src="${base}js/json2.js"></script>
    <style>
        body{overflow: hidden;}
    </style>
</head>
<body>
<script>
    var _dialogArguments;
    if(typeof window.showModalDialog === "function"){
        //这是用模态窗口打开的
        _dialogArguments = window.dialogArguments;
    }else{
        _dialogArguments = window.data;
    }
</script>
<div class="easyui-layout" data-options="fit:true">
    <div data-options="region:'north',border:false" style="text-align:left;padding:10px;background: #F1F5FB;height:43px;overflow:hidden;">
        <c:if test="${not isView}">
            <easyui:linkButton name="保存" iconKey="save" onClick="doSave();"/>
            <easyui:linkButton name="取消保存" iconKey="back" onClick="cancelSave();"/>
        </c:if>
        <c:if test="${isView}">
            <easyui:linkButton name="关闭" iconKey="back" onClick="window.close();"/>
        </c:if>
    </div>
    <div data-options="region:'center',border:false">
        <jsp:doBody/>
    </div>
</div>
<script type="text/javascript" src="${base}js/public.js?0.5"></script>
<script type="text/javascript" src="${base}js/http.js?0.1"></script>
<script>
    function doProcessFormResponse(data){
        if(typeof data === "undefined"){
            alert("保存有错，请与开发人员联系!");
            return;
        }
        if(data.hasErrors){
            alert(data.message);
            return;
        }
        alert("保存成功！");
        if(typeof doAfterSave === "function"){
            doAfterSave(data,_dialogArguments);
        }else if(typeof _dialogArguments.parent.reloadList === "function"){
            _dialogArguments.parent.reloadList();
        }
        window.close();
    }
    function doSave(){
        if(submitting){
            alert("表单正在提交，请稍候...");
            return;
        }
        var $frm =$("#"+formId);
        if($frm.form("validate")){
            if(typeof doBeforeSave === "function"){
                var canContinue = doBeforeSave($frm,_dialogArguments);
                if(typeof canContinue === "boolean" && !canContinue){
                    return;
                }
            }
            $frm.form('submit');
        }
    }
    function cancelSave(){
        if(window.confirm("确认要放弃此次修改吗？")){
            window.returnValue = -1;
            window.close();
        }
    }
    $(function(){
        //获取父页面传过来的参数
        if(_dialogArguments){
            var title = _dialogArguments.title;
            if(typeof title == "string" && title!=""){
                window.document.title = title;
            }else{
                window.document.title = "${title}";
            }
        }
    });
</script>
</body>
</html>


